package pers.xuehongyan.useat.server.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

/**
 * @author xuehongyan
 */
public class TOTPUtils {
    InputStream in;

    String[] getCmd(String secret) {
        return new String[]{"/Users/xuehongyan/Workspace/totp_demo/test", secret};
    }

    public String generateTOTP(String secret) {
        try {
            Process process = Runtime.getRuntime().exec(getCmd(secret));
            in = process.getInputStream();
            BufferedReader read = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
            String line = read.readLine();
            process.getOutputStream().close();
            return line;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}
